<template>
  <!--  <h2>全文检索</h2>-->
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="24" :xs="24">
        <el-card class="box-card">
          <div style="display: flex; float: right;">
            <el-button v-if="showCategory" type="primary" plain icon="el-icon-arrow-up" size="mini" @click="fold">折叠
            </el-button>
            <el-button v-else type="primary" plain icon="el-icon-arrow-down" size="mini" @click="expand">展开
            </el-button>
          </div>
          <el-row :gutter="10" class="mb8" ref="queryForm" v-show="showCategory" style="width: 95%; position: relative;">
            <div class="searchCheck">
              <div style="width: 8%">
                <label style="width: 80%; display: inline-block; text-align-last: justify;">全宗名称</label>
                <font style="width: 10%;vertical-align: top; display: inline-block;">：</font>
              </div>

              <div style="flex-wrap: wrap; width:90%" :style="isSize">
                <el-select v-model="qzh" placeholder="请选择" @change="onqzhChangeTap($event)">
                  <el-option v-for="i in qzhList" :key="i.FONDS_CODE" :label="i.FONDS_NAME" :value="i.FONDS_CODE">
                  </el-option>
                </el-select>
                <div>
                  <div v-if="this.qzh != '-1'">
                    <div class="block" v-for="(item, index) in archivesCategory" :key="item.value"
                      @click="handleClickArchives(index, item)"
                      :style="{ color: item.color, backgroundColor: item.backgroundColor }">
                      {{ item.label }}
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="searchCheck" v-show="showSearch">
              <div style="width: 8%">
                <label style="width: 80%; display: inline-block; text-align-last: justify;"></label>
                <font style="width: 10%;vertical-align: top; display: inline-block;"></font>
              </div>

              <div style="flex-wrap: wrap; width:90%" :style="isSize">
                <el-form :inline="true" style="margin-top:6px;">
                  <el-form-item label="" v-for="(item, index) in listFrom" :key="index">
                    <span slot="label">{{ item.FIELD_CAPTION }} </span>
                    <input_item :item="item" :listFrom="listFrom" @onChangeTap="onChangeTap" :inputType="1"
                      :sourceType="1" :inputParams="queryParam"></input_item>
                  </el-form-item>
                </el-form>
              </div>
            </div>

            <div style="display: flex;margin-top:6px;" @mouseleave="hideHistory">
              <div class="searchCheck" style="width: 50%; margin-right:1%">
                <div style="width: 17%">
                  <label style="width: 80%; display: inline-block; text-align-last: justify;">综合查询</label>
                  <font style="width: 10%;vertical-align: top; display: inline-block;">：</font>
                </div>
                <div class="line-main" :style="divStyle" style="display: flex; width: 90%">
                  <div class="tagClass" style="display: flex; margin-top: 5px;" :style="divStyle">
                    <el-tag v-for="(tag, index) in tags" :key="index" closable :type="tag.type" @close="removeTag(tag)"
                      style="margin: 5px;">
                      {{ tag.name }}
                    </el-tag>
                  </div>
                  <el-input v-model="keyword" placeholder="请输入关键字" @mouseover.native="showHistory" :maxlength="100"
                    style="margin: 2px; width: 100%" @keyup.enter.native="handleQuery" @keyup.space.native="addTag" />
                </div>
                <div class="card" style="display: none" id="card">
                  <div style="display: flex; padding: 2%">
                    <div style="display: flex; font-size: 14px">
                      <label
                        style="display: inline-block; text-align-last: justify; height: 100%; white-space: nowrap;">最近搜索</label>
                      <font style="width: 10%;vertical-align: top; display: inline-block;">：</font>
                    </div>
                    <div>
                      <span class="history" :style="isSize" type="info" v-for="(item, index) in searchHistory"
                        :key="index" @click="selectHistory(item)">{{ item }}</span>
                    </div>
                  </div>
                </div>
              </div>
              <div>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                <el-button type="success" plain icon="el-icon-view" @click="knowledgeGraph"
                  v-hasPermi="['archive:qwjs:knowledgeGraph']">知识图谱</el-button>
              </div>
              <div style=" width: 20%; text-align: right;" v-show="isShowTip">
                <span style="color: grey;">单击右键可以进行收藏</span>
              </div>
            </div>
            <div class="searchCheck" style="width: 50%; margin-right: 5%; margin-top: 10px">
              <div style="width: 16%"></div>
              <div style="display: flex; width: 90%">
                <el-radio-group v-model="radio">
                  <el-radio :label="8" v-hasPermi="['archive:qwjs:vague']">模糊查询</el-radio>
                  <el-radio :label="9" v-hasPermi="['archive:qwjs:accurate']">精确查询</el-radio>
                </el-radio-group>
              </div>
            </div>
          </el-row>
          <el-row :gutter="10" class="mb8" ref="refbut" style="width: 95%;">
            <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-edit-outline" v-hasPermi="['archive:qwjs:registration']"
                @click="registration">登记</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-download" v-hasPermi="['archive:mljs:allDownload']"
                @click="allDownloadTap">批量下载</el-button>
            </el-col>
            <el-col :span="1.5" style="float: right">
              <!--              <el-button type="warning" plain icon="el-icon-setting"  v-hasPermi="['archive:qwjs:tablehead']" @click="headerSettings" v-show="isShowButton">表头设置</el-button>-->
              <el-button type="warning" icon="el-icon-setting" circle v-hasPermi="['archive:qwjs:tablehead']"
                @click="headerSettings" v-show="isShowButton"></el-button>
            </el-col>
          </el-row>
          <div class="showtable">
            <!-- 知识图谱 start -->
            <KnowledgeGraph style="height: 580px" v-show="isShowGraph" ref="knowledgeRef" :knowTable="knowTable"
              :total="total" :archivesCategory="archivesCategory" @getKnowList="getKnowList"
              :tableHeaderList="tableHeaderList"></KnowledgeGraph>
            <!-- 知识图谱 end -->
            <!-- 表格 start -->
            <tableList v-if="tableHeight && tableHeaderList.length > 0 && !isShowGraph" :tableHeaderList="tableHeaderList"
              :sourceType="'1'" :isSelection="true" @handleSelectionChange="handleSelectionChange" :tableData="tableData"
              :loading="loading" ref="tableList" :tableHeight="tableHeight" @celldblclick="celldblclick"
              @sortChange="sortChange" :isRetrieval="isRetrieval" @handleBorrow="handleBorrow"
              @rowcontextmenu="rowcontextmenu" @handleRegister="handleRegister"></tableList>
            <!-- 表格 end -->
            <pagination v-show="total > 0 && !isShowGraph" :total="total" :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize" @pagination="getQuery" />
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!--start  组件详情 -->
    <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbData"
      @detailsHandleClose="detailsHandleClose">
    </jianDetailsOpen>
    <!--end 组件详情 -->
    <!-- start 组卷\项目详情 -->
    <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbData"
      @detailsHandleClose="detailsHandleClose" :isDelete="1"></juanDetailsOpen>
    <!-- end 组卷\项目详情 -->
    <!-- start  目录打印 -->
    <vPrint v-if="printOpen" :open="printOpen" @closeDelDialog="closeDelDialog" :tableHeaderList="tableHeaderList"
      :printList="printList"></vPrint>
    <!-- end  目录打印 -->

    <!-- start 表头设置 -->
    <transFer :title="headerTitle" :dataChecked="myDataChecked" :cities="HeaderData" :isHeaderOrder='true'
      @determine="submitHeader" @closeFilter="closeHeader" :open="headerOpen">
    </transFer>
    <!-- end 表头设置 -->

    <!-- start 登记单 -->
    <Register :open="registerOpen" @closeDelDialog="closeRegister" ref="registerRef"></Register>
    <!-- end 登记单 -->
  </div>
</template>

<script>
import tableList from "@/components/tableListSearch/index.vue"
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' //卷详情
import queryCriteriaList from "@/components/queryCriteriaList/index.vue"
import input_item from "@/components/input/index.vue"
import {
  getSearchList, addWords,
  batchInsert,
  getcateidbyid,
  getInfo,
  getKeyWords, getCategoryList, getQueryList, getShowList, queryAuthority, fullText
} from "@/api/archive/retrieval/fullTextSearch";
import { getqzhList } from "@/api/archive/retrieval/catalogueSearch";
import vPrint from "@/components/printComponent";
import { addMyCollection } from "@/api/archive/liyong/myCollection";
import transFer from "@/components/transFer/index.vue"
import { addhead, gethead } from "@/api/archive/digitalizeReceive/archiveRecycleBin";
import { addReRegister } from "@/api/archive/retrieval/catalogueSearch";
import Register from "@/views/archive/retrieval/catalogueSearch/register";
import KnowledgeGraph from "@/views/archive/retrieval/fullTextSearch/knowledgeGraph";
import { getRouters } from "@/api/menu.js"
export default {
  name: "index",
  components: { KnowledgeGraph, queryCriteriaList, tableList, jianDetailsOpen, juanDetailsOpen, vPrint, input_item, transFer, Register },
  data() {
    return {
      showSearch: false,
      showCategory: true,
      // 档案门类
      archivesCategory: [],
      archivesCategoryIndex: -1,
      keyword: undefined,
      // 是否展示历史记录
      showCard: false,
      // 历史记录
      searchHistory: [],
      listFrom: [], //查询框列表

      tableHeight: "",
      tableHeaderList: [], //table表头数据
      tableData: [],//table列表数据
      knowTable: [],
      // 选中数组
      ids: [],
      id: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: true,
      isRetrieval: true,
      queryParams: {
        pageNum: 0,
        pageSize: 10
      },
      queryParam: {},
      label: "",
      total: 0,
      jianDetailsOpen: false,//件详情弹窗
      juanDetailsOpen: false,//卷详情弹窗

      printOpen: false, //打印弹出传
      printList: [],
      isShowTip: false, // 是否展示提示

      // 首页的门类选择
      category: '',

      headerTitle: '表头设置',
      // 展示右侧数据
      myDataChecked: [],
      headerData: [],
      HeaderData: [],
      headerOpen: false,
      isShowButton: true,

      registerOpen: false,
      isShowGraph: false,

      radio: 8,
      tags: [],
      divStyle: '',
      qzhList: [],
      qzh: "",
      selectionString:[]
    }
  },
  computed: {
    isSize() {
      if (this.$store.getters.size == 'small') {
        this.size = 'font-size: 12px;'
      } else {
        this.size = 'font-size: 14px;'
      }
      return this.size
    },
  },
  watch: {
    tags: {
      handler(val) {
        if (val.length > 0) {
          setTimeout(() => {
            // 获取 tagClass 元素
            const tagClassElement = document.querySelector('.tagClass');
            // 获取 tagClass 元素的宽度
            const tagClassWidth = tagClassElement.offsetWidth;
            // 获取 line-main 元素
            const lineMainElement = document.querySelector('.line-main');

            // 获取 line-main 元素的宽度
            const lineMainWidth = lineMainElement.offsetWidth;

            // 计算 tagClass 宽度占 line-main 宽度的百分比
            const tagClassPercentage = (tagClassWidth / lineMainWidth) * 100;
            console.log(tagClassPercentage)
            // 如果 tagClass 宽度超过 line-main 宽度的80%
            if (tagClassPercentage > 50) {
              this.divStyle = 'flexWrap: wrap'
            } else {
              this.divStyle = 'flexWrap: nowrap'
            }
          }, 100)
        } else {
          this.divStyle = 'flexWrap: nowrap'
        }
      },
      deep: true
    }
  },
  mounted() {
    // 在页面加载时，获取路由传递的查询参数
    this.keyword = this.$route.query.keyword || '';
    this.category = this.$route.query.category || '';
    // if(this.$route.query.keyword != undefined) {
    //   this.handleQuery()
    // }
  },
  created() {
    //判断是否有收藏功能
    // getRouters().then(res => {
    //   this.routeList = res.data
    //   console.log(this.hasRoute("myCollection",this.routeList),"wode shouc")
    // })'
    const permissions = this.$store.getters.permissions;
    if (permissions.indexOf('archive:qwjs:vague') !== -1) {
      this.radio = 8
    } else if (permissions.indexOf('archive:qwjs:accurate') !== -1) {
      this.radio = 9
    }

    this.queryParams.menuId = this.$route.meta.menuId
    if (this.archivesCategory.length != 0) {
      this.archivesCategory[0].color = '#5377d7';
      this.archivesCategory[0].backgroundColor = '#e1eaff';
      this.archivesCategoryIndex = 0
    }
    if (this.archivesCategory.length != 0) {
      this.archivesCategory[0].color = '#5377d7';
      this.archivesCategory[0].backgroundColor = '#e1eaff';
      this.archivesCategoryIndex = 0
    }
    this.getqzhListPost();
    this.getAuthority()
    this.getHistory()
  },

  methods: {

      //批量下载
      allDownloadTap() {
      var that = this;


      if (!this.multiple) {

        var data = [];
        for (var i in this.selectionString) {
          data.push({
            "subtablename": this.selectionString[i].sub_table_name,
            "id": this.selectionString[i].ID
          })


        }

       

          var dalist={
            dalist:data
          }
         var dalist= JSON.stringify(dalist)
              this.download('/archive/list/query/download/electronics', {dalist}
            , `wjb_${new Date().getTime()}.zip`)
     

  
      } else {
        this.$modal.msgWarning('请选择下载数据哦！')
      }


    },
    hasRoute(path, routeList) {
      !routeList && (routeList = this.routeList, console.log('执行'))

      for (let i = 0; i < routeList.length; i++) {

        if (routeList[i].path == path) {
          console.log(routeList[i].path, path, "shuju")
          return true
        }
        if (routeList[i].children) {

          let flag = this.hasRoute(path, routeList[i].children)
          console.log(path, routeList[i].children, "000")
          if (flag) {
            return flag
          }
        }
      }

      return false
    },
    //全宗号列表
    getqzhListPost() {
      getqzhList(this.$route.meta.menuId).then(res => {
        if (res.code == 200) {
          this.qzhList = res.data;
          this.qzh = res.data[0].FONDS_CODE;
          this.queryParams.qzh = res.data[0].FONDS_CODE;
          this.getCategory();
          // this.handleQuery()
        }
      })
    },
    //全宗号列表下拉事件
    onqzhChangeTap(val) {
      console.log(val, "sdklfjsdkljfklsdfjklsdfjklsjdf")
      if (val == '-1') {

      }
      this.queryParams.fileField = undefined;
        this.queryParams.groupId = undefined;

      this.keyword = undefined
      this.tags = []
      this.queryParams.queryParameters = undefined
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.queryParam = {};
      this.showSearch = false;
      this.queryParams.qzh = val;
      this.getCategory()

    },
    getHistory() {
      getInfo().then(res => {
        this.form = {
          // userName: res.user.userName,
          userId: res.user.userId,
          menuId: this.$route.meta.menuId
        }
        getKeyWords(this.form).then(response => {
          this.searchHistory = response.data
        })
      })
    },
    // 获取收藏权限
    getAuthority() {
      queryAuthority().then(response => {
        if (response.data == true) {
          this.isShowTip = true
        } else {
          this.isShowTip = false
        }
      })
    },
    //动态设置table的高度
    tableHeightData() {
      this.$nextTick(
        () => {
          let h = document.documentElement.clientHeight
          h = h - 250
          if (this.$refs.queryForm) { // 页面上如果有面包屑区域徐减去它的高度
            h = h - this.$refs.queryForm.$el.offsetHeight
          }

          if (this.$refs.refbut) { // 页面上如果有分页区域徐减去它的高度
            h = h - this.$refs.refbut.$el.offsetHeight
          }
          this.tableHeight = h > 410 ? h : 410 // 根据自己项目定高度
          return h
        }
      )
    },
    //折叠事件
    fold() {
      this.showCategory = false
    },
    //展开事件
    expand() {
      this.showCategory = true
    },
    showHistory() {
      this.showCard = true;
      var d1 = document.getElementById('card')
      // 获取 line-main 元素
      const lineMainElement = document.querySelector('.line-main');
      // 获取 line-main 元素的高度
      const lineMainHeight = lineMainElement.offsetHeight;
      d1.style.cssText = 'display: block;  transform: translate(0%, ' + lineMainHeight + '%);'
    },
    hideHistory() {
      var d1 = document.getElementById('card')
      d1.style.cssText = 'display: none;'
    },
    // 获取门类
    getCategory() {
      getCategoryList({
        menuId: this.$route.meta.menuId,
        qzh: this.queryParams.qzh
      }).then(response => {
        var data = response.data.map(item => {
          return {
            // 门类id
            value: item.ID,
            // 门类名称
            label: item.NAME,
            // 元数据方案id
            id: item.GROUP_ID,
            // 类型
            type: item.TYPE,
            color: '#606266',
            backgroundColor: 'white'
          }
        })
        var categoryId = response.data.map(item => item.ID).toString();
        this.archivesCategory = []
        this.archivesCategory = [{
          label: "全部",
          color: '#606266',
          backgroundColor: 'white',
          value: categoryId
        }]
        this.archivesCategory.push(...data)
        if (this.$route.query.keyword != undefined) {
          if (this.category.value != undefined) {
            for (let i = 0; i < this.archivesCategory.length; i++) {
              if (this.archivesCategory[i].value == this.category.value) {
                this.archivesCategory[i].color = '#5377d7';
                this.archivesCategory[i].backgroundColor = '#e1eaff';
                this.archivesCategoryIndex = i
                this.queryParams.groupId = this.category.id
                // 门类id
                this.queryParams.categoryId = this.category.value
                // label
                this.label = this.category.label
                this.getSearch()
                this.handleQuery()
              } else if (this.category.value == '-1' && this.archivesCategory[i].label == '全部') {
                this.archivesCategory[i].color = '#5377d7';
                this.archivesCategory[i].backgroundColor = '#e1eaff';
                this.archivesCategoryIndex = i
                this.queryParams.groupId = this.category.id
                // 门类id
                this.queryParams.categoryId = this.archivesCategory[i].value
                // label
                this.label = this.category.label
                this.handleQuery()
              }
            }
          } else {
            if (this.archivesCategory.length != 0) {
              this.archivesCategory[0].color = '#5377d7';
              this.archivesCategory[0].backgroundColor = '#e1eaff';
              this.archivesCategoryIndex = 0
            }
            this.queryParams.categoryId = categoryId;
            this.handleQuery()
          }
        } else {
          if (this.archivesCategory.length != 0) {
            this.archivesCategory[0].color = '#5377d7';
            this.archivesCategory[0].backgroundColor = '#e1eaff';
            this.archivesCategoryIndex = 0
          }
          this.queryParams.categoryId = categoryId;
        }
      })
    },
    // 档案门类变换
    handleClickArchives(index, value) {
      if (this.archivesCategoryIndex !== -1) {
        // 恢复上次点击的div为黑色并去掉下划线
        this.archivesCategory[this.archivesCategoryIndex].color = '#606266';
        this.archivesCategory[this.archivesCategoryIndex].backgroundColor = 'white';
      }
      // 将当前点击的div变为蓝色并添加下划线
      this.archivesCategory[index].color = '#5377d7';
      this.archivesCategory[index].backgroundColor = '#e1eaff';

      // 更新archivesCategoryIndex
      this.archivesCategoryIndex = index;
      // 元数据方案id
      this.queryParams.groupId = value.id
      // 门类id
      this.queryParams.categoryId = value.value
      // 菜单id
      this.queryParams.menuId = this.$route.meta.menuId
      // label
      this.label = value.label
      if (value.label == '全部') {
        this.showSearch = false;
        this.isShowButton = true
      } else {
        this.showSearch = true;
        this.isShowButton = false
      }
      this.keyword = undefined
      this.tags = []
      this.queryParams.queryParameters = undefined
      this.queryParams.fileField = undefined
      // console.log(this.queryParams, '-----------------')
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.queryParam = {};
      if (value.label != '全部') {
        this.getSearch()
      }
      this.listFrom = [] // 查询条件
      this.tableHeaderList = [] // 表头
      this.tableData = [] // 列表数据
      this.knowTable = []
      this.total = 0

    },
    // 搜索条件
    getSearch() {
      this.listFrom = []
      if (this.queryParams.categoryId != undefined && this.queryParams.menuId != undefined) {
        getQueryList(this.queryParams).then(response => {
          if (response.data) {
            this.showSearch = true
            this.listFrom = response.data;
          } else {
            this.showSearch = false
          }
        })
      }
    },
    // 表头
    getTableList() {
      var that = this;
      getShowList(that.queryParams).then(response => {
        if (response.data != undefined) {
          that.tableHeaderList = response.data;
          var fileField = []
          for (var i in response.data) {
            fileField.push(response.data[i].FIELD_NAME)
          }
          that.queryParams.fileField = fileField.toString()
        }
        that.getQuery();
      })
    },
    selectHistory(item) {
      this.keyword = item;
    },
    //onChangeTap时间
    onChangeTap(data) {
      var dataArr = ""
      if (data.val != undefined) {
        dataArr = data.queryParams;
      } else {
        dataArr = data;
      }
      // if (this.queryParams.length > 0) {
      //   for (var i in this.queryParams) {
      //     if (Object.keys(this.queryParams[i]).toString() == Object.keys(data).toString()) {
      //       this.queryParams.splice(i, 1)
      //     }
      //   }
      //   this.queryParams = dataArr;
      // } else {
      //   this.queryParams = dataArr;
      // }
    },
    // 搜索按钮
    handleQuery() {
      this.addTag()
      this.isShowGraph = false
      this.loading = true;
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.queryParams.order = undefined;
      this.queryParams.type = '-1'
      if (this.$refs.tableList != undefined) {
        this.$refs.tableList.clearSort()
      }
      this.hideHistory()
      var searchcolumn = []
      for (var k in this.listFrom) {
        for (var i in this.queryParam) {
          if (this.queryParam[i] != null) {
            if (this.listFrom[k].FIELD_NAME == i) {
              if (this.listFrom[k].SHOWTYPE == 3 && this.listFrom[k].IS_QUERY == 4) {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME,
                  "value": this.queryParam[i][0],
                  "valueTwo": this.queryParam[i][1],
                })
              } else if (this.listFrom[k].SHOWTYPE == 7 || this.listFrom[k].SHOWTYPE == 8 || this.listFrom[k].SHOWTYPE == 10) {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME + "_ID",
                  "value": this.queryParam[i + "_ID"],
                })
              } else {
                searchcolumn.push({
                  "queryType": this.listFrom[k].IS_QUERY,
                  "showType": this.listFrom[k].SHOWTYPE,
                  "column": this.listFrom[k].FIELD_NAME,
                  "value": this.queryParam[i],
                })
              }
            }
          }
        }
      }
      if (searchcolumn != undefined && searchcolumn.length != 0) {
        var column = searchcolumn.filter(item => { return item.value !== '' })
        this.queryParams.queryParameters = column
      } else {
        this.queryParams.queryParameters = []
      }
      if (this.tags.length > 0) {
        var arr = []
        for (let i = 0; i < this.tags.length; i++) {
          arr.push({
            queryType: this.tags[i].radio,
            value: this.tags[i].name
          })
        }
        const keyWords = arr.map(item => item.value).join(" ");
        this.saveKeyword(keyWords)
        this.queryParams.queryParameters.push(...arr)
        console.log(this.queryParams, "111------------------------------------------")
      }
      this.loading = true;
      this.getTableList()
      this.getHistory()
    },
    // 保存综合检索关键字
    saveKeyword(keyword) {
      this.form = {
        keyWords: keyword,
        menuId: this.$route.meta.menuId
      }
      addWords(this.form).then(response => { })
    },
    // 重置按钮
    resetQuery() {
      this.keyword = ''
      this.tags = []
      this.queryParams.queryParameters = undefined
      this.queryParam = {};
      this.queryParams.order = undefined;
      if (this.$refs.tableList != undefined) {
        this.$refs.tableList.clearSort()
      }
      this.handleQuery()
    },
    // 表格
    getQuery() {
      console.log(this.queryParams, "00000000000000000")
      this.hideHistory()
      getSearchList(this.queryParams).then(response => {
        console.log(response, "-----------")
        this.knowTable = JSON.parse(JSON.stringify(response.rows))
        for (let i = 0; i < response.rows.length; i++) {
          var data = []
          this.typeOption = []
          if (response.rows[i].EFILE_COUNT > 0) {
            data.push(...[
              { value: '1', label: '电子件' }
            ])
          }
          if (response.rows[i].IS_ENTITY == '是') {
            data.push(...[
              { value: '0', label: '实体件' }
            ])
          }
          if (response.rows[i].EFILE_COUNT < 0 && response.rows[i].IS_ENTITY != '是') {
            data = []
          }
          this.typeOption.push(...data)
          response.rows[i].typeOption = this.typeOption
          if (response.rows[i].typeOption.length > 0) {
            response.rows[i].borrowType = response.rows[i].typeOption[0].value
          }
        }
        this.tableData = response.rows;
        const keyWords = this.tags.map(item => item.name).join(" ");
        if (keyWords != "" && keyWords != undefined) {
          const words = keyWords.match(/\S+/g);
          if (words != null) {
            this.tableData.forEach(row => {
              // 遍历每一列数据
              Object.keys(row).forEach(column => {
                if (column != 'is_borrowing_car' && column != 'sub_table_name' && column != 'ID' && column != 'borrowType') {
                  var value = ''
                  if (row[column] != null) {
                    if (typeof (row[column]) == 'string') {
                      value = row[column];
                    } else {
                      value = row[column].toString();
                    }
                  }
                  // 判断当前列数据是否包含查询条件中的任意一个元素
                  let matchFound = words.some(item => value.includes(item));
                  if (matchFound) {
                    // 使用<span>标签将匹配到的字段改为红色
                    words.forEach(item => {
                      // let highlightedValue = value.replace(new RegExp(item, "gi"), "<span style='color: red;'>$&</span>");
                      let escapedItem = item.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&')
                      let highlightedValue = value.replace(new RegExp(escapedItem, "gi"), "<span style='color: red;'>$&</span>");
                      value = highlightedValue;
                    });
                    row[column] = value;
                  }
                }
              });
            });
          }
        }
        this.total = response.total;
        this.loading = false;
        this.tableHeightData();
      })
    },
    //是否选择数据
    handleSelectionChange(ids, single, multiple,selection) {
      console.log(selection)
      this.ids = ids.toString();
      this.single = single;
      this.multiple = multiple;
      this.id = selection.map(item => item.ID).toString();
      this.selectionString = selection
    },
    //双击列表进入详情页面
    celldblclick(row) {
      this.subStr = this.getLastIndexOf(row.sub_table_name);
      var level = "";
      var type = "";
      var label = ""
      var regex = /<span style='color: red;'>|<\/span>/g;
      if (this.getLastIndexOf(row.sub_table_name) == "F") {  //F 件
        level = 0
        type = "f"
        // label = row.TITLE.replace(regex, '');
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
      } else if (this.getLastIndexOf(row.sub_table_name) == "V") { //卷
        level = 1
        type = "v"
        // label = row.TITLE.replace(regex, '');
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
      } else { //项目
        level = 3
        type = "x"
        // label = row.XMMC.replace(regex, '');
        if (row.XMMC != undefined && row.XMMC != null && row.XMMC != '') {
          label = row.XMMC.replace(regex, '');
        }
      }
      console.log(row, "00000")
      var arr = [];
      if (row.is_borrowing_car == '1') {
        const keyWords = this.tags.map(item => item.name).join(" ");
        console.log(keyWords, "圣诞快乐荆防颗粒束带结发克里斯丁")
        if (keyWords.length > 0) {
          if (keyWords != "" && keyWords != undefined) {
            const words = keyWords.split(/\s+/);
            for (let i = 0; i < words.length; i++) {
              arr.push(words[i])
            }
          }
        }
        fullText({ queryList: arr, daId: row.ID }).then(res => {
          this.celldbData = {
            id: row.ID,
            categoryId: row.categoryId,
            menuId: this.$route.meta.menuId,
            sub_table_name: row.sub_table_name,
            label: label,
            level: level,
            ifSub_table_name: row.sub_table_name,
            isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
            tableHeaderList: this.tableHeaderList,
            isBorrowingCar: row.is_borrowing_car,
            isElectronMatch: res, // 电子件匹配信息
            isShowjieyue:true,
          }
          this.$nextTick(() => {
            if (this.subStr == "F") {  //F 进入件详情
              this.jianDetailsOpen = true;
            } else { //进入卷详情 和项目详情
              this.juanDetailsOpen = true
            }
          })
        })
      } else {
        this.celldbData = {
          id: row.ID,
          categoryId: row.categoryId.replace(regex, ''),
          menuId: this.$route.meta.menuId,
          sub_table_name: row.sub_table_name,
          label: label,
          level: level,
          ifSub_table_name: row.sub_table_name,
          isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
          tableHeaderList: this.tableHeaderList,
          isBorrowingCar: row.is_borrowing_car
        }
        this.$nextTick(() => {
          if (this.subStr == "F") {  //F 进入件详情
            this.jianDetailsOpen = true;
          } else { //进入卷详情 和项目详情
            this.juanDetailsOpen = true
          }
        })
      }
    },
    // 获取字符串中最后一个_前面的内容和获取最后一个"_"之后的内容
    getLastIndexOf(sub_table_name) {
      // 获取字符串中最后一个_前面的内容:
      var str = sub_table_name;
      var index = str.lastIndexOf("_");
      var strData = str.substring(0, index);
      //获取最后一个"_"之后的内容
      var index1 = strData.lastIndexOf("_");
      strData = strData.substring(index1 + 1, strData.length);
      return strData;
    },
    //关闭详情页面
    detailsHandleClose() {
      this.jianDetailsOpen = false;
      this.juanDetailsOpen = false;
    },
    //排序
    sortChange(val) {
      // console.log(val, "ksdfjkl")
      this.queryParams.order = val;
      // console.log(this.queryParams, "+++")
      this.getQuery();
    },
    // 加入借阅车
    handleBorrow(row) {
      var isdaBox = ""
      var type = "";
      var regex = /<span style='color: red;'>|<\/span>/g;
      if (this.getLastIndexOf(row.sub_table_name) == "F") {  //F 件
        isdaBox = "0"
        type = "f"
      } else if (this.getLastIndexOf(row.sub_table_name) == "V") { //卷
        isdaBox = "1"
        type = "v"
      } else { //项目
        isdaBox = "1"
        type = "x"
      }
      this.form = {
        id: row.ID,
        type: type
      }
      getcateidbyid(this.form).then(response => {
        const data = [{
          daType: row.borrowType,
          categoryId: response.data,
          daId: row.ID,
          isdaBox: isdaBox,
          archiveType: type,
          subTableName: row.sub_table_name
        }]
        batchInsert(data).then(response => {
          this.$modal.msgSuccess("加入借阅车成功")
        })
      })
    },
    // 目录
    printTap() {
      this.printList = [];
      if (this.id != undefined && this.id != null && this.id != "") {
        this.printOpen = true
        var idsData = this.id.split(",")
        for (var i in this.tableData) {
          for (var j in idsData) {
            if (this.tableData[i].ID == idsData[j]) {
              this.printList.push(this.tableData[i])
            }
          }
        }
      } else {
        this.$message({ message: '请选择要打印的数据哦', type: 'warning' })
      }
    },
    //关闭
    closeDelDialog() {
      this.printOpen = false;//打印
    },
    rowcontextmenu(row) {
      // console.log(row)
      var label = ''
      var IS_EFILE = ''
      var IS_ENTITY = ''
      var regex = /<span style='color: red;'>|<\/span>/g;
      if (this.getLastIndexOf(row.sub_table_name) == "F") {  //F 件
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
      } else if (this.getLastIndexOf(row.sub_table_name) == "V") { //卷
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
      } else { //项目
        if (row.XMMC != undefined && row.XMMC != null && row.XMMC != '') {
          label = row.XMMC.replace(regex, '');
        }
      }
      var dh = row.DH
      if (row.DH != undefined && row.DH != '' && row.DH != null) {
        dh = dh.replace(regex, '')
      }
      if (row.EFILE_COUNT > 0) {
        IS_EFILE = '是'
      } else {
        IS_EFILE = '否'
      }
      if (row.IS_ENTITY == '是') {
        IS_ENTITY = '是'
      } else {
        IS_ENTITY = '否'
      }
      this.form = {
        subTableName: row.sub_table_name,
        daNum: dh,
        daContent: label,
        daId: row.ID,
        isEfile: IS_EFILE,
        isEntity: IS_ENTITY
      }
      if (this.isShowTip) {
        this.$modal.confirm('是否确认收藏所选档案？').then(function () { }).then(() => {
          addMyCollection(this.form).then(res => {
            if (res.code == "200") {
              this.$modal.msgSuccess("收藏成功");
            }
          })
        }).catch(() => { });
      }
    },

    // 表头设置
    headerSettings() {
      this.headerOpen = true
      this.myDataChecked = []
      this.HeaderData = []
      this.queryParams.type = 0
      getShowList(this.queryParams).then(response => {
        if (response.data != undefined) {
          this.headerData = response.data.map((item, index) => {
            return {
              fieldCaption: item.FIELD_CAPTION,
              fieldName: item.FIELD_NAME,
              key: index,
              isOrder: 'none'
            }
          })
          gethead({ tablemenuId: this.$route.meta.menuId, zltype: this.queryParams.type, qzh: this.queryParams.qzh }).then(res => {
            if (res.msg != null) {
              var arr = res.msg.split(',')
              const result = arr.reduce((acc, item) => {
                const [key, value] = item.split(" ");
                acc[key] = value;
                return acc;
              }, {});
              for (let i = 0; i < arr.length; i++) {
                if (this.headerData.filter((item) => item.fieldName == Object.keys(result)[i]).length != 0) {
                  const data = this.headerData.filter((item) => item.fieldName == Object.keys(result)[i])
                  data[0].isOrder = Object.values(result)[i]
                  this.myDataChecked = this.myDataChecked.concat(data)
                }
              }
            }
            this.HeaderData = this.headerData
          })
        }
      })
    },
    // 保存
    submitHeader(value, isOrder) {
      this.form = {
        tablemenuId: this.$route.meta.menuId,
        zltype: '0',
      }
      var arr = []
      for (var j = 0; j < value.length; j++) {
        for (var i = 0; i < isOrder.length; i++) {
          if (isOrder[i].key == value[j]) {
            const str = isOrder[i].code + "$" + isOrder[i].isOrder
            arr.push(str)
          }
        }
      }
      this.form.content = arr.toString()
      this.form.qzh = this.qzh;
      addhead(this.form).then(res => {
        this.headerOpen = false
        this.myDataChecked = []
        this.headerData = []
        this.handleQuery()
      })
    },
    closeHeader() {
      this.headerOpen = false
      this.myDataChecked = []
      this.headerData = []
    },

    // 借阅登记单
    handleRegister(row) {
      var label = ''
      var type = "";
      var regex = /<span style='color: red;'>|<\/span>/g;
      if (this.getLastIndexOf(row.sub_table_name) == "F") {  //F 件
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
        type = "f"
      } else if (this.getLastIndexOf(row.sub_table_name) == "V") { //卷
        if (row.TITLE != undefined && row.TITLE != null && row.TITLE != '') {
          label = row.TITLE.replace(regex, '');
        }
        type = "v"
      } else { //项目
        if (row.XMMC != undefined && row.XMMC != null && row.XMMC != '') {
          label = row.XMMC.replace(regex, '');
        }
        type = "x"
      }
      var dh = row.DH
      if (row.DH != undefined && row.DH != '' && row.DH != null) {
        dh = dh.replace(regex, '')
      }
      var data = {
        id: row.ID,
        type: type
      }
      getcateidbyid(data).then(response => {
        row.categoryId = response.data
        this.form = {
          daId: row.ID,
          title: label,
          dh: dh,
          daMsg: JSON.stringify(row),
          subTableName: row.sub_table_name,
        }
        addReRegister(this.form).then(res => {
          this.$modal.msgSuccess('添加登记单档案成功')
        })
      })
    },
    // 登记
    registration() {
      this.registerOpen = true
      this.$nextTick(() => {   //此函数执行时所有的DOM挂载和渲染都已完成
        this.$refs.registerRef.init();     //获取子组件中init方法并将父组件数据传递给子组件
      });
    },
    closeRegister() {
      this.registerOpen = false
    },
    // 知识图谱
    knowledgeGraph() {
      this.handleQuery()
      const keyWords = this.tags.map(item => item.name).join(" ");
      this.$nextTick(() => {
        this.$refs.knowledgeRef.init(keyWords)
      })
      this.isShowGraph = true
    },
    getKnowList(param) {
      this.queryParams.pageNum = param.pageNum
      this.queryParams.pageSize = param.pageSize
      this.getQuery()
    },

    addTag() {
      if (this.keyword != "" && this.keyword != undefined) {
        if (this.keyword.trim() !== '') {
          const words = this.keyword.split(/\s+/);
          for (let i = 0; i < words.length; i++) {
            if (words[i] != '') {
              this.tags.push({ name: words[i], type: 'success', radio: this.radio });
            }
          }
          this.keyword = '';
        }
      }
    },
    removeTag(tag) {
      const index = this.tags.indexOf(tag);
      if (index !== -1) {
        this.tags.splice(index, 1);
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.box-card {
  height: calc(100vh - 120px) !important;
  overflow-y: scroll;
}

.searchCheck {
  //margin: 15px auto 0px;
  margin-bottom: 2px;
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  line-height: 36px;
  font-size: 14px;
  color: #606266;
}

.block {
  padding: 3px 8px 3px 8px;
  white-space: nowrap;
  border-radius: 2px;
  border: solid 1px #e3e3e3;
  // font-size: 14px;
  color: #606266;
  text-align: center;
  margin: 0 8px 4px 0;
  display: inline-table;
  line-height: 25px;
}

.searchCheck .el-input {
  margin-bottom: 2px;
  width: 90%
}

.card {
  overflow: hidden;
  outline: none;
  width: 42%;
  display: flex;
  margin-left: 8%;
  border: 1px solid #ddd;
  box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);
  border-radius: 2px;
  height: 100px;
  overflow-y: scroll;
  z-index: 9999;
  transform: translate(0%, 40%);
  background-color: white;
  position: absolute;
}

.card .el-card__body {
  display: flex;
}

.history {
  padding: 3px 8px 3px 8px;
  border-radius: 2px;
  font-size: 10px;
  margin: 0 8px 4px 0;
  display: inline-table;
  height: 10px;
  line-height: 12px;
  color: #999;
  border: 1px solid #ccc;
  background-color: #f4f4f5;
}

.history:hover {
  background-color: white;
}

.line-main {
  border: 1px solid #DCDFE6;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  // overflow: hidden;
  position: relative;
  line-height: 32px;
  width: 85%;
  border-radius: 3px;
}</style>
